//
//  Status.swift
//  WeChat
//
//  Created by 梁迪 on 15/12/18.
//  Copyright © 2015年 梁迪. All rights reserved.
//

import UIKit

class Status: NSObject {
    //微博创建时间
    var created_at:String?
    var id:Int64 = 0
    var text:String?
    var source:String?
    
    //用户模型
    
    var user:User?
    
    var pic_urls:[[String:String]]?{
        
        didSet{
            
            guard let array = pic_urls else{
                
                return
            }
            
            imageURLs = [NSURL]()
            for item in array{
               var urlString = item["thumbnail_pic"]!
                urlString = urlString.stringByReplacingOccurrencesOfString("thumbnail", withString: "square")
                
                let url = NSURL(string: urlString)!
                
               imageURLs?.append(url)
                
                
            }
            
            
        }
    }
    
    
    
    // 将配图数组转化为纯 url 对象
    var imageURLs:[NSURL]?
    
    var retweeted_status: Status?
    
    //构造方法 KVC 设置值
    init(dict:[String:AnyObject]) {
        
        super.init()
        setValuesForKeysWithDictionary(dict)
        
        
    }
    
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            if let dict = value as?[String:AnyObject]{
                user = User(dict: dict)
                
                
                
            }
            
            return
        }
        
        
        if key == "retweeted_status" {
            if let dict = value as? [String:AnyObject]{
                retweeted_status = Status(dict: dict)
                
                return
            }
            
            
            
            
        }
        
        
        
        
        
        super.setValue(value, forKey: key)
        
        
        
        
        
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    //重写 description
    override var description:String{
        let keys = ["created_at","id","text","source","user"]
        return dictionaryWithValuesForKeys(keys).description
        
        
        
    }
    
    

}
